 $(document).ready(function () {
	var layerFrame;
	bootbox.setDefaults({locale:framework.locale});
	
	// 复选框
    $('.i-checks').iCheck({ checkboxClass: 'icheckbox_square-green',  radioClass: 'iradio_square-green',  });
    // 选择所有
    $("input[name='checkAll']").on('ifChanged',function(){
		$("input[name='ids']").iCheck($(this).is(":checked") == true ? 'check':'uncheck');  
	});
    
    //跳转
    var $listForm = $("#listForm");
	var $pageTotal = $("#pageTotal");
	var $pageSize = $("#pageSize");
	var $pageNumber = $("#pageNumber");
	// 页码跳转
	$.pageSkip = function(pageNumber) {
		$pageNumber.val(pageNumber);
		$listForm.submit();
		return false;
	}
	
	// 搜索
 	$(".loippi-search-button").click(function(){
 		//点击搜索按钮，将页码重置为第一页
 		if($("#pageNumber")[0]){
 			$("#pageNumber").val(1);
 		}
 		//获取搜索下拉框的选中值
 		document.getElementsByName("statusKey").values($("#selectstatus option:selected").val());
 		$listForm.submit();
 	});
    
    // 删除单条记录
    $(".btn-delete-loippi").click(function(){
    	var $this = $(this);
    	 bootbox.confirm(message("admin.dialog.deleteConfirm"), function(result) {
		 	if(result){
		 		$.ajax({
					url: "delete.jhtml",
					type: "POST",
					data: {ids:$this.attr('data-id')},
					dataType: "json",
					cache: false,
					success: function(message) {
						window.setTimeout(function() {
							window.location.reload();
						}, 1000);
					}
				});
		 	}
        }); 
    });
    
   // 删除多条记录
   $(".btn-delete-loippi-group").click(function(){
   		var $checkeds = jQuery($("input[name='ids']:checked"));
   		
   		if($checkeds.length == 0){art.warn('请选择删除记录！');return;}
   		
   		bootbox.confirm(message("admin.dialog.deleteConfirm"), function(result) {
		 	if(result){
		 		$.ajax({
					url: "delete.jhtml",
					type: "POST",
					data: $checkeds.serialize(),
					dataType: "json",
					cache: false,
					success: function(message) {
						art.message(message);
						if (message.type == "success") {
							window.setTimeout(function() {
								window.location.reload();
							}, 1000);
						}
					}
				});
		 	}
        }); 
   });

     //实现排序
     //0：升序
     $(".fa-caret-up").on("click",function(){
         var orderProperty=$(this).siblings("input").val();
         $(".orderProperty").val(orderProperty);
         $(".sort").val(0);
         $listForm.submit();
     });
     //1:降序
     $(".fa-caret-down").on("click",function(){
         var orderProperty=$(this).siblings("input").val();
         $(".orderProperty").val(orderProperty);
         $(".sort").val(1);
         $listForm.submit();
     });
     
   //重写搜索功能 lwb (原因：在非第一页时搜索会附带页码参数，所以不能直接执行submit提交)
     $("#submit_search").on("click",function(){
  	   $pageNumber.val(1);//重置为第一页
  	   $listForm.submit();
     });
});